package visiopuce.ui.tree;

import java.util.List;

import org.eclipse.swt.graphics.Image;

import visiopuce.objets.Analyse;
import visiopuce.objets.Prelevement;
import visiopuce.service.AnalyseService;
import visiopuce.service.AnalyseServiceImpl;

public class PrelevementNode extends TreeNode {

	private Prelevement prelevement;

	public PrelevementNode(Prelevement prelevement) {
		this(null, prelevement);
	}

	public PrelevementNode(ITreeNode parent, Prelevement prelevement) {
		super(parent);
		this.prelevement = prelevement;
	}

	public String getName() {
		String txt = prelevement.getNumeroPrelevement();
		if (prelevement.getTypePrelevement() != null){
			txt += " ("+prelevement.getTypePrelevement().getLibelle()+")";
		}
		return txt;
	}

	public Image getImage() {
		// return new Image(new Display(),"icons/Prelev.png");
		return null;
	}

	@Override
	protected void createChildren(List children) {
		AnalyseService analyseService = AnalyseServiceImpl.getInstance();
		List<Analyse> analyses = analyseService.findAllByidPrelevement(prelevement.getIdPrelevement());
		for (Analyse analyse : analyses) {
			children.add(new AnalyseNode(this, analyse));
		}

	}

	public Prelevement getPrelevement() {
		return prelevement;
	}

}
